package com.ldzy.controller;

import com.ldzy.domain.Book;
import com.ldzy.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
public class Bookcontrller {
   @Autowired
    public BookService bookService;
    @RequestMapping("/book")
    public ModelAndView findBookById(Integer id){
        System.out.println("book");
        ModelAndView modelAndView=new ModelAndView();
        Book book=bookService.findBookById(id);
        modelAndView.setViewName("books");
        modelAndView.addObject("book",book);
        return  modelAndView;
    }
    @RequestMapping("/books")
    public ModelAndView findBooksById(){
        ModelAndView modelAndView=new ModelAndView();
       List<Book> bookList=bookService.findAllBookBy();
        modelAndView.setViewName("books");
        modelAndView.addObject("books",bookList);
        return  modelAndView;
    }
}
